import 'package:finance_app/src/entities/coa_entity.dart';

coaEntityFromJson(CoaEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['group_name'] != null) {
		data.groupName = json['group_name'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['coaAccountHeader'] != null) {
		data.coaAccountHeader = (json['coaAccountHeader'] as List).map((v) => CoaCoaAccountHeader().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> coaEntityToJson(CoaEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['group_name'] = entity.groupName;
	data['name'] = entity.name;
	data['status'] = entity.status;
	data['coaAccountHeader'] =  entity.coaAccountHeader?.map((v) => v.toJson())?.toList();
	return data;
}

coaCoaAccountHeaderFromJson(CoaCoaAccountHeader data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['coa_account_type_id'] != null) {
		data.coaAccountTypeId = json['coa_account_type_id'] is String
				? int.tryParse(json['coa_account_type_id'])
				: json['coa_account_type_id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['coaAccountDetail'] != null) {
		data.coaAccountDetail = (json['coaAccountDetail'] as List).map((v) => CoaCoaAccountHeaderCoaAccountDetail().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> coaCoaAccountHeaderToJson(CoaCoaAccountHeader entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['coa_account_type_id'] = entity.coaAccountTypeId;
	data['name'] = entity.name;
	data['status'] = entity.status;
	data['coaAccountDetail'] =  entity.coaAccountDetail?.map((v) => v.toJson())?.toList();
	return data;
}

coaCoaAccountHeaderCoaAccountDetailFromJson(CoaCoaAccountHeaderCoaAccountDetail data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['coa_account_type_id'] != null) {
		data.coaAccountTypeId = json['coa_account_type_id'] is String
				? int.tryParse(json['coa_account_type_id'])
				: json['coa_account_type_id'].toInt();
	}
	if (json['coa_account_header_id'] != null) {
		data.coaAccountHeaderId = json['coa_account_header_id'] is String
				? int.tryParse(json['coa_account_header_id'])
				: json['coa_account_header_id'].toInt();
	}
	if (json['account_code'] != null) {
		data.accountCode = json['account_code'].toString();
	}
	if (json['external_account_code'] != null) {
		data.externalAccountCode = json['external_account_code'].toString();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'];
	}
	if (json['crdr_nature'] != null) {
		data.crdrNature = json['crdr_nature'].toString();
	}
	if (json['business_type'] != null) {
		data.businessType = json['business_type'].toString();
	}
	if (json['parent_account_id'] != null) {
		data.parentAccountId = json['parent_account_id'] is String
				? int.tryParse(json['parent_account_id'])
				: json['parent_account_id'].toInt();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['open_balance'] != null) {
		data.openBalance = json['open_balance'] is String
				? num.tryParse(json['open_balance'])
				: json['open_balance'];
	}
	if (json['balance'] != null) {
		data.balance = json['balance'] is String
				? num.tryParse(json['balance'])
				: json['balance'];
	}
	if (json['as_at'] != null) {
		data.asAt = json['as_at'];
	}
	if (json['status'] != null) {
		data.status = json['status'].toString();
	}
	if (json['edit_disallowed'] != null) {
		data.editDisallowed = json['edit_disallowed'];
	}
	if (json['with_subaccount_id'] != null) {
		data.withSubaccountId = json['with_subaccount_id'] is String
				? int.tryParse(json['with_subaccount_id'])
				: json['with_subaccount_id'].toInt();
	}
	if (json['maps'] != null) {
		data.maps = (json['maps'] as List).map((v) => v).toList().cast<dynamic>();
	}
	if (json['hardValue'] != null) {
		data.hardValue = json['hardValue'] is String
				? num.tryParse(json['hardValue'])
				: json['hardValue'];
	}
	return data;
}

Map<String, dynamic> coaCoaAccountHeaderCoaAccountDetailToJson(CoaCoaAccountHeaderCoaAccountDetail entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['coa_account_type_id'] = entity.coaAccountTypeId;
	data['coa_account_header_id'] = entity.coaAccountHeaderId;
	data['account_code'] = entity.accountCode;
	data['external_account_code'] = entity.externalAccountCode;
	data['name'] = entity.name;
	data['description'] = entity.description;
	data['crdr_nature'] = entity.crdrNature;
	data['business_type'] = entity.businessType;
	data['parent_account_id'] = entity.parentAccountId;
	data['currency_code'] = entity.currencyCode;
	data['open_balance'] = entity.openBalance;
	data['balance'] = entity.balance;
	data['as_at'] = entity.asAt;
	data['status'] = entity.status;
	data['edit_disallowed'] = entity.editDisallowed;
	data['with_subaccount_id'] = entity.withSubaccountId;
	data['maps'] = entity.maps;
	data['hardValue'] = entity.hardValue;
	return data;
}

coaByGroupEntityFromJson(CoaByGroupEntity data, Map<String, dynamic> json) {
	if (json['group_name'] != null) {
		data.groupName = json['group_name'].toString();
	}
	if (json['coaAccountDetail'] != null) {
		data.coaAccountDetail = (json['coaAccountDetail'] as List).map((v) => CoaCoaAccountHeaderCoaAccountDetail().fromJson(v)).toList();
	}
	return data;
}

Map<String, dynamic> coaByGroupEntityToJson(CoaByGroupEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['group_name'] = entity.groupName;
	data['coaAccountDetail'] =  entity.coaAccountDetail?.map((v) => v.toJson())?.toList();
	return data;
}